/**
 * Created by 陈奇 on 2015/3/9.
 */
var express = require('express');
var router = express.Router();
var db = require('./conn'); //先引入数据库链接


router.get('/', function(req, resLogin) {
    function fun(connection, sql) {
        connection.query(sql, function(error, res) {
            var user = []; //用户列表
            var talk = []; //评论列表
            var books = []; //书名

            if (res.length != 0) {
                for (var i in res) {
                    user.push(res[i].UserName);
                    talk.push(res[i].talkabout);
                    books.push(res[i].bookname);
                }
            }
            resLogin.render('readerGarden', {
                user: user,
                talk: talk,
                book: books
            });
        });
        connection.release();
    }
    db.pool.getConnection(function(err, connection) {

        var sql = 'select * from bbs';
        fun(connection, sql);
    });
});

module.exports = router;